Program to Insert the text file into Oracle
import java.io.*;
import java.sql.*;
public class Sample
{
public static void main(String args[]) throws IOException
{
Connection con=null;
FileInputStream fin=null;
PreparedStatement ps=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:vision","scott","tiger");
File f=new File(“vision.txt”);
fin=new FileInputStream(f);
ps=con.prepareStatement(“insert into vision values(?,?,?)”);
ps.setInt(1,100);
ps.setString(2,”vision.txt”);
ps.setAsciiStream(3,fin,(int)f.length());
ps.executeUpdate();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(con!=null)
con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}
Program on binary Stream
import java.io.*;
import java.sql.*;
public class Sample
{
public static void main(String args[]) throws IOException
{
Connection con=null;
PreparedStatement ps=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:vision","scott","tiger");
File f=new File(“vision.dat”);
int l=(int)f.length();
InputStream is=(InputStream) new FileInputStream(f);
File f1=new File(“xyz.dat”);
int l1=(int)f1.length();
InputStream is1=(InputStream) new FileInputStream(f1);
String s=“insert into vision values(?,?,?)”;
con.setAutoCommit(false);
ps=con.prepareStatement(s);
ps.setInt(1,100);
ps.setBinaryStream(2,is,l);
ps.setBinaryStream(3,is1,l1);
ps.executeUpdate();
con.commit();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(con!=null)
con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}
Program on Character Stream
import java.io.*;
import java.sql.*;
public class Sample
{
public static void main(String args[]) throws IOException
{
Connection con=null;
Reader fr=null;
PreparedStatement ps=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:vision","scott","tiger");
File f=new File(“vision.txt”);
int l=(int)f.length();
fr=(Reader) new BufferedReader(new FileReader(f));
ps=con.prepareStatement(“insert into vision values(?,?,?)”);
ps.setInt(1,100);
ps.setCharacterStream(2,fr,l);
ps.executeUpdate();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(con!=null)
con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}